package com.woniuxy.controller;

import com.woniuxy.util.AmapService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

/**
 * @program: tsm
 * @description:
 * @create: 2024-10-22 16:52
 **/
@RestController
@RequestMapping("/amap")
public class AmapController {
    @Resource
    private AmapService amapService;

    public AmapController(AmapService amapService) {
        this.amapService = amapService;
    }

    @GetMapping("/search")
    public String search(@RequestParam String keyword) {
        return amapService.searchPlace(keyword);
    }

    @GetMapping("/staticMap")
    public ResponseEntity<byte[]> getStaticMap(@RequestParam String location) {
        byte[] imageBytes = amapService.getStaticMap(location);
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_PNG)  // 设置响应类型为 PNG
                .body(imageBytes);  // 返回字节流
    }
}